cmake_minimum_required(VERSION 2.8.3)
project(roll)


set(CMAKE_BUILD_TYPE "Release")
# set(CMAKE_CXX_FLAGS "-std=c++14")
set(CMAKE_CXX_STANDARD 14) # necessary for some systems
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g -pthread")

find_package(catkin REQUIRED COMPONENTS
  tf
  roscpp
  rospy
  cv_bridge
  # pcl library
  pcl_conversions
  # pcl_ros # same as # find_package(PCL 1.7 REQUIRED) 
  # msgs
  std_msgs
  sensor_msgs
  geometry_msgs
  nav_msgs
  message_generation
  visualization_msgs
)

find_package(OpenMP REQUIRED)
# voxel grid error
# find_package(PCL 1.8 REQUIRED PATHS ~/Softwares/pcl-1.8/install NO_DEFAULT_PATH)
# find_package(PCL 1.9 REQUIRED PATHS /home/binpeng/Software/pcl-1.9/install NO_DEFAULT_PATH)
find_package(PCL 1.7 REQUIRED) # 
find_package(OpenCV REQUIRED QUIET)
find_package(GTSAM REQUIRED QUIET)
find_package(Ceres REQUIRED)

# message(STATUS ${PCL_INCLUDE_DIR})
# message(STATUS ${PCL_LIBRARIES})
add_message_files(
  DIRECTORY msg
  FILES
  cloud_info.msg
)

add_service_files(
  DIRECTORY srv
  FILES
  save_map.srv
)

generate_messages(
  DEPENDENCIES
  geometry_msgs
  std_msgs
  nav_msgs
  sensor_msgs
)

catkin_package(
  INCLUDE_DIRS include
  DEPENDS PCL GTSAM
  CATKIN_DEPENDS
  message_runtime
  std_msgs
  nav_msgs
  geometry_msgs
  sensor_msgs
  visualization_msgs
)

# include directories
include_directories(
	include
	${catkin_INCLUDE_DIRS}
	${PCL_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
	${GTSAM_INCLUDE_DIR}
  ${CERES_INCLUDE_DIRS}
)
message("catkin include dirs:  ${catkin_INCLUDE_DIRS}")
message("catkin libs:  ${catkin_LIBRARIES}")
# link directories
link_directories(
	include
	${PCL_LIBRARY_DIRS}
  ${OpenCV_LIBRARY_DIRS}
  ${GTSAM_LIBRARY_DIRS}
)

###########
## Build ##
###########
# ScanRegistration
add_executable(${PROJECT_NAME}_scanRegistration src/scanRegistration.cpp)
add_dependencies(${PROJECT_NAME}_scanRegistration ${catkin_EXPORTED_TARGETS} ${PROJECT_NAME}_generate_messages_cpp)
target_link_libraries(${PROJECT_NAME}_scanRegistration ${catkin_LIBRARIES} ${PCL_LIBRARIES} ${OpenCV_LIBS})

# Mapping Optimization
add_executable(${PROJECT_NAME}_mapOptmization src/mapOptmization.cpp src/globalOpt.cpp)
add_dependencies(${PROJECT_NAME}_mapOptmization ${catkin_EXPORTED_TARGETS} ${PROJECT_NAME}_generate_messages_cpp) # ~_gencpp is the file generated by the service
target_compile_options(${PROJECT_NAME}_mapOptmization PRIVATE ${OpenMP_CXX_FLAGS})
target_link_libraries(${PROJECT_NAME}_mapOptmization ${catkin_LIBRARIES} ${PCL_LIBRARIES}
                      ${OpenCV_LIBS} ${OpenMP_CXX_FLAGS} ${DBoW3_LIBS} gtsam ${CERES_LIBRARIES})

# # fastlio mapping
# add_executable(${PROJECT_NAME}_mapOptimizationWithFastlio src/mapOptimizationWithFastlio.cpp)
# add_dependencies(${PROJECT_NAME}_mapOptimizationWithFastlio  ${catkin_EXPORTED_TARGETS} ${PROJECT_NAME}_generate_messages_cpp) # ~_gencpp is the file generated by the service
# target_compile_options(${PROJECT_NAME}_mapOptimizationWithFastlio  PRIVATE ${OpenMP_CXX_FLAGS})
# target_link_libraries(${PROJECT_NAME}_mapOptimizationWithFastlio  ${catkin_LIBRARIES} ${PCL_LIBRARIES}
#                       ${OpenCV_LIBS} ${OpenMP_CXX_FLAGS} ${DBoW3_LIBS} gtsam ${CERES_LIBRARIES})

# ground-truth mapping: still no good even using deskewed clouds from fastlio
add_executable(${PROJECT_NAME}_mapOptimizationGT src/mapOptimizationGT.cpp)
add_dependencies(${PROJECT_NAME}_mapOptimizationGT  ${catkin_EXPORTED_TARGETS} ${PROJECT_NAME}_generate_messages_cpp) # ~_gencpp is the file generated by the service
target_compile_options(${PROJECT_NAME}_mapOptimizationGT  PRIVATE ${OpenMP_CXX_FLAGS})
target_link_libraries(${PROJECT_NAME}_mapOptimizationGT  ${catkin_LIBRARIES} ${PCL_LIBRARIES}
                      ${OpenCV_LIBS} ${OpenMP_CXX_FLAGS} ${DBoW3_LIBS} gtsam ${CERES_LIBRARIES})

# # lidar odometry
# add_executable(${PROJECT_NAME}_lidarOdometry src/lidarOdometry.cpp)
# add_dependencies(${PROJECT_NAME}_lidarOdometry ${catkin_EXPORTED_TARGETS} ${PROJECT_NAME}_generate_messages_cpp)
# target_link_libraries(${PROJECT_NAME}_lidarOdometry ${catkin_LIBRARIES} ${PCL_LIBRARIES} ${OpenMP_CXX_FLAGS} ${OpenCV_LIBS} ${CERES_LIBRARIES})
# target_compile_options(${PROJECT_NAME}_lidarOdometry PRIVATE ${OpenMP_CXX_FLAGS})


